from mongoengine import StringField, ObjectIdField, ListField
from utils.mongoengine import DataDocument as Document
from utils.decorators import cached_property


class EnterPrise(Document):
    """
        为企业提供服务；支持多个企业；各个企业的数据不互相影响
    """
    _model_desc_ = 'EnterPrise'
    name = StringField(required=True, primary_key=True)
    vname = StringField()
    desc = StringField()
    contact_info = StringField()
    manager_name = StringField()
    modules = ListField(StringField())
    type = StringField(verbose_name="公司类型，基本公司为root")
    meta = {'strict': True}

    @cached_property
    def manager(self):
        from app.user.models import User
        return User.ori_objects.get(nickname=self.manager_name, enterprise_id=self.name, is_deleted__ne=True)
